<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		  <title>工作日志</title>
		  <link rel="stylesheet" href="../../layui/css/layui.css">
		<script src="../../layui/layui.js"></script>
		<script src="../../js/jquery3.js"></script>
	</head>
	<style>
		.toolbar {
            border: 1px solid #ccc;
        }
        .text {
            border: 1px solid #ccc;
            min-height: 400px;
        }
		#dv1{
			width: 1000px;
			margin: 30px auto;
		}
    </style>
	<body>
		
		<div id="dv1">
			 <input type="text" name="title" required id="title" lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input" style="width:830px;height: 50px;border-radius: 10px;display: inline;" >
			 <div style="display: inline-block; padding-left: 30px;"><button type="button" class="layui-btn layui-btn-lg layui-btn-radius layui-btn-normal" id="addLog">保存日志</button></div>
			<hr>
			<div id="toolbar-container" class="toolbar"></div>
			<p>&nbsp;</p>
			<div id="text-container" class="text" ></div>
		</div>


		<script type="text/javascript" src="../../js/wangEditor.min.js"></script>
		<script type="text/javascript">
			const E = window.wangEditor
			const editor = new E('#toolbar-container', '#text-container') // 传入两个元素
			
			// 注意，先配置 height ，再执行 create()
			editor.create()
			
		</script>

	<script>
		$.post("/user/getSelf", {}, function (data) {
			if (data != null) {
				$("#addLog").click(function (){

				let title = $("#title").val().trim();
				let content = $(".w-e-text").html();

					$.post("/log/addLog",{l_title:title,l_content:content,u_id:data.u_id},function (res){

						layui.use('layer', function () {
							var layer = layui.layer;
							if (res == "success") {
								layer.msg('添加成功',{icon:1,time:2000}, function(){
									location.href="findLog.html"
								});
							} else {
								layer.msg('添加异常，请重试',{icon:2,time:2000}, function(){
									window.location.reload(); //刷新父页面
								});
							}
						})

					})
				})

			 } else {
			alert("未登录，请先登录")
			location.href = "../login/login.html"
		}
		})
	</script>
	</body>


</html>
